# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>

pkgname=go-tools
epoch=4
pkgver=0.14.0
pkgrel=1
pkgdesc='Developer tools for the Go programming language'
arch=(loong64 x86_64)
url='https://golang.org/'
license=(BSD)
depends=(glibc)
makedepends=(git go)
_commit=3f4194ee29d7db9b59757dfff729ef55cf89661c	#refs/tags/v0.14.0
source=(go-tools::git+https://go.googlesource.com/tools#commit=$_commit)
sha256sums=('SKIP')

_tools=(benchcmp callgraph compilebench digraph eg fiximports
        go-contrib-init godex godoc goimports gomvpkg gorename gotype 
        goyacc guru html2article present ssadump stringer toolstash)

prepare() {
    cd go-tools
    mkdir -p bin/
}

build() {
  cd go-tools
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -mod=readonly -modcacherw"
  go build -ldflags "-compressdwarf=false -linkmode external" -o bin/ ./cmd/...
}

check() {
  cd go-tools
  # Needs to be updated and godoc is failing the test suite
  # See https://github.com/golang/go/issues/35690
  go test ./cmd/...  || true
}

package() {
  cd go-tools
  for tool in ${_tools[@]}; do
    install -Dm755 bin/$tool "$pkgdir/usr/bin/$tool"
  done

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
